<?php

namespace App\Http\Controllers\Admin\Author;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class AccountController extends Controller
{
    public function getIndex(Request $request)
    {
    	$id = $request->session()->get('id');
    	$res = DB::table('hs_member')->where('id',$id)->select('id','account')->first();
    	// dd($res);
    	return view('admin.author.account.index',['res'=>$res]);
    }

    public function getEdit($id,$account)
    {
    	// return $id;
    	return view('admin.author.account.edit',['account'=>$account,'id'=>$id]);
    }

    public function postCash(Request $request)
    {
    	//获取体现金额
    	$tx = $request->input('tx');
    	//获取余额最大值
    	$account = $request->input('account');
    	$id = $request->input('id');
    	// dd($id);


    	if(is_numeric($tx)){
	    	//判断体现金额是否大于余额
	    	if($tx > $account){
	    		return back()->with('error','余额不足');
	    	}else{
	    		$res = DB::table('hs_account')->insert(['apply'=>$tx,'uid'=>$id,'treat'=>0]);
	    		if($res){
	    			return redirect('/admin/account/index')->with('success','申请成功，等待审核');
	    		}else{
	    			return back()->with('error','申请失败');
	    		}
	    	}
	    }else{
	    	return back()->with('error','请填入数值');
	    }	
    	// dd($request->all());
    }

    public function getTreat(Request $request)
    {
    	//获取作者id
    	$id = $request->session()->get('id');
    	$res = DB::table('hs_account')->where('uid',$id)->get();
    	return view('admin.author.account.indexz',['res'=>$res]);
    }

}
